package com.koocloud.electroplatemanage.controller;


import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.QRCode;
import com.koocloud.electroplatemanage.service.AnalysisQRCodeService;
import com.koocloud.electroplatemanage.utils.Base64Util;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

@RestController
public class AnalysisQRCodeController {
    static Logger log = Logger.getLogger("getQRCodeInfo");
    @Autowired
    AnalysisQRCodeService analysisQRCodeService;
    @PostMapping("/getQRCodeInfo")
    public ResponseTemplate getQRCodeInfo(@RequestBody QRCode qrCode) throws UnsupportedEncodingException {
        // 获取加密的二维码内容
        String qrCodeContentStr = qrCode.getQrCodeContent();
        //log.info("加密零件二维码信息内容："+qrCodeContentStr);
        // 解析二维码
        String qrCodeContent= Base64Util.decode(qrCodeContentStr);
        //log.info("解密后零件二维码信息内容："+qrCodeContent);
        return analysisQRCodeService.getQrContentByWorkOrderNumber(qrCodeContent);
    }
}
